
public class ReserveNode {
	public static void main(String[] args) {
		Node node1 = new Node(1);
		Node node2 = new Node(2);
		Node node3 = new Node(3);
		Node node4 = new Node(4);
		Node node5 = new Node(5);
		Node node6 = new Node(6);
		Node node7 = new Node(7);
		Node node8 = new Node(8);
		node1.next = node2;
		node2.next = node3;
		node3.next = node4;
		node4.next = node5;
		node5.next = node6;
		node6.next = node7;
		node7.next = node8;
		reverse(node1);
		System.out.println(node8);
	}

	private static void reverse(Node node) {
		Node head = node;
		Node tail = null;
		Node tmp = node;
		int i = 0;
		while(tmp != null) {
			if (i == 0) {
				head = tmp;
			}
			if(i == 2) {
				Node a = tmp;
				tmp = tmp.next;
				Node t = reverse(head, a);
				if(tail != null) {
					tail.next = a;
				}
				tail = head;
				i = -1;
			}else {
				tmp = tmp.next;
			}
			i++;
			
		}
	}
	private static Node reverse(Node node, Node tail) {
		Node tmp = null;
		Node n = node;
		while(n != null && n != tail) {
			Node n1  = n.next;
			n.next = tmp;
			tmp = n;
			n = n1;
		}
		tail.next = tmp;
		return node;
	}

	static class Node {
		public Node(int value) {
			this.value = value;
		}

		int value;
		Node next;

		@Override
		public String toString() {
			return "Node [value=" + value + ", next=" + next + "]";
		}
	}
}
